package com.kemai.designmode.ui
import android.os.Bundle
import com.kemai.common.adapter.ItemClickListener
import com.kemai.common.ui.BaseActivity
import com.kemai.designmode.R
import com.kemai.designmode.entry.Fruit
import com.kemai.designmode.factory.method.AppleMethodFactory
import com.kemai.designmode.factory.method.BananaMethodFactory
import com.kemai.designmode.factory.method.OrangeMethodFactory
import com.kemai.designmode.template.CashShoppingCart

//模板方法模式调用(在父类中编排主流程，将步骤实现延迟到子类去实现)
class TemplateActivity : BaseActivity(), ItemClickListener {
    private val studyContent = arrayOf("点我购物",)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_common_content)
        findViewById()
        setTiTle("模板方法模式")
        setAdapterContent(studyContent,TemplateActivity@this,TemplateActivity@this)
    }

    override fun itemClick(position: Int) {
        var products = ArrayList<Fruit>()
        val appleMethodFactory = AppleMethodFactory()
        val bananaMethodFactory = BananaMethodFactory()
        val orangeMethodFactory = OrangeMethodFactory()
        val apple = appleMethodFactory.getFruit()
        val banana = bananaMethodFactory.getFruit()
        val orange = orangeMethodFactory.getFruit()
        products.add(apple)
        products.add(banana)
        products.add(orange)
        when(position){
            0->{
                val cashShoppingCart = CashShoppingCart(products)
                cashShoppingCart.submitOrder()

            }

        }

    }

}